package com.example.transactiondemo.controller;

import com.example.transactiondemo.service.BankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bank")
public class BankController {

    @Autowired
    private BankService bankService;

    @PostMapping("/transfer")
    @Transactional(propagation = Propagation.REQUIRED)
    public String transfer(@RequestParam String fromAccount, @RequestParam String toAccount, @RequestParam double amount) {
        //从账户A001扣钱
        bankService.transfer1(fromAccount, amount);
        //给账户A002加钱
        bankService.transfer2(toAccount, amount);
        return "Transfer successful";
    }
}
